package com.controller.zk;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.aliyun.core.annotation.Path;
import com.bean.zk.Power;
import com.service.zk.PowerService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@Controller
public class PowerController {

    @Resource
    private PowerService powerService;

    @RequestMapping("/page/getpowers/{rid}")
    @ResponseBody
    public List<Power> getallPowers(@PathVariable String rid){
        return powerService.getAllPowers(rid);
    }
    @RequestMapping("/page/returnIds/{rid}")
    @ResponseBody
    public boolean getallPowers(@RequestParam String permList , @PathVariable String rid, HttpServletRequest request){
        String[] checkedList = permList.split(",");
        Integer[] checked = new Integer[checkedList.length];
        for (int i = 0; i < checkedList.length; i++) {
            if (checkedList[i].length()!=0) {
                checked[i] = Integer.parseInt(checkedList[i]);
            }
        }
        powerService.dealPower(checked,rid,request);
        return false;
    }


}
